/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-24     takeout       the first version
 */
#ifndef APPLICATIONS_SENSORS_H_
#define APPLICATIONS_SENSORS_H_

/* sensor trigger value */
#define SENSOR_NO_TRIGGER_VALUE 0x01
#define SENSOR_TRIGGER_VALUE    0x00

/* pin config */
#define SMOKE_MASK              0x01
#define ALCOHOL_GAS_MASK        0x02
#define NATURAL_GAS_MASK        0x04
#define AIR_QUALITY_MASK        0x08

/* mask config */
#define SMOKE_PIN               37 //PC6
#define ALCOHOL_GAS_PIN         38 //PC7
#define NATURAL_GAS_PIN         39 //PC8
#define AIR_QUALITY_PIN         40 //PC9

/* domoticz idx config */
#define SMOKE_IDX               1
#define ALCOHOL_GAS_IDX         4
#define NATURAL_GAS_IDX         3
#define AIR_QUALITY_IDX         2

#define DEFINE_A_SENSOR(name) \
    {\
        (#name),\
        (name ## _PIN),\
        (name ## _MASK),\
        (name ## _IDX),\
        (0),\
    }

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a)   (sizeof(a) / sizeof(a[0]))
#endif

typedef struct _sensor_object_t {
    const char *name;
    rt_base_t   pin;
    rt_base_t   mask;
    rt_base_t   idx;
    rt_base_t   last_status;
} sensor_object_t;

int sensors_init(void *arg);

int sensors_get_status(void);

int sensors_clear_status(void);

#endif /* APPLICATIONS_SENSORS_H_ */
